package com.example.zhaoshuang.rippledemo.slice;

import com.example.zhaoshuang.rippledemo.HintPopupWindow;
import com.example.zhaoshuang.rippledemo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.window.dialog.ToastDialog;

import java.util.ArrayList;

public class MainAbilitySlice extends AbilitySlice {

    private HintPopupWindow hintPopupWindow;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        findComponentById(ResourceTable.Id_root).setClickedListener(component -> hintPopupWindow.showPopupWindow(component));

        Button button = (Button) findComponentById(ResourceTable.Id_button);
        button.setClickedListener(v -> hintPopupWindow.showPopupWindow(v));

        Image imageView = (Image) findComponentById(ResourceTable.Id_imageView);
        imageView.setClickedListener(v -> {
            //弹出选项弹窗
            hintPopupWindow.showPopupWindow(v);
        });

        //下面的操作是初始化弹出数据
        ArrayList<String> strList = new ArrayList<>();
        strList.add("选项item1");
        strList.add("选项item2");
        strList.add("选项item3");

        ArrayList<Component.ClickedListener> clickList = new ArrayList<>();
        Component.ClickedListener clickListener = v -> new ToastDialog(this).setText("点击事件触发").show();
        clickList.add(clickListener);
        clickList.add(clickListener);
        clickList.add(clickListener);
        clickList.add(clickListener);

        //具体初始化逻辑看下面的图
        hintPopupWindow = new HintPopupWindow(this, strList, clickList);

        findComponentById(ResourceTable.Id_btn_test).setClickedListener(component -> hintPopupWindow.showPopupWindow(component));

        findComponentById(ResourceTable.Id_bottom).setClickedListener(component -> hintPopupWindow.showPopupWindow(component));
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
